package org.example.chain_of_responsibility_pattern;

/**
 * @author lyq
 * @description
 * @since 2025-03-10 11:47
 */

public class Client {
  public static void main(String[] args) {
    // 1. 创建处理者链
    Handler lowHandler = new LowLevelHandler();
    Handler mediumHandler = new MediumLevelHandler();
    Handler highHandler = new HighLevelHandler();

    // 构建链式关系：low → medium → high
    lowHandler.setNext(mediumHandler).setNext(highHandler);

    // 2. 创建不同级别的请求
    Request request1 = new Request("LOW", "申请购买办公用品（金额: 500元）");
    Request request2 = new Request("MEDIUM", "申请团队建设活动（金额: 5000元）");
    Request request3 = new Request("HIGH", "申请购买服务器（金额: 200000元）");
    Request request4 = new Request("URGENT", "紧急请求（无匹配处理者）");

    // 3. 将请求传递给链的起点（由链自动分配处理者）
    lowHandler.handleRequest(request1);  // LowLevelHandler 处理
    lowHandler.handleRequest(request2);  // MediumLevelHandler 处理
    lowHandler.handleRequest(request3);  // HighLevelHandler 处理
    lowHandler.handleRequest(request4);  // 无处理者能处理
  }
}
